<?php

	
	include_once 'json_function.php';
	$ini_array = parse_ini_file("config/config.ini");
		
	$conn = @mysqli_connect($ini_array["host"], $ini_array["username"], $ini_array["password"], $ini_array["db_name"]) or die("cann't connect the mysql db");
	mysqli_set_charset($conn, "utf8");
	ini_set('default_charset', "UTF-8");
	
	$viewDate = $_POST["viewDate"];
		
	date_default_timezone_set("PRC");
	$viewSql = "select appointment_no, First_name, Surname, appointment_datetime from appointment, patient where appointment.Patient_no=patient.Patient_no and type=2 and DATE_FORMAT(appointment_datetime, '%d/%m/%Y') = '".$viewDate."'";

	$result = mysqli_query($conn, $viewSql);
	$data = "{\"data\":[";
	$count = 0;
	while( $row = mysqli_fetch_array($result)){
		if( $count != 0 ){
			$data .= ",";
		}else{
			$count = 1;
		}
		$data .= "{\"appointmentNo\":\"".$row["appointment_no"]."\",";
		$data .= "\"patientFirstName\":\"".$row["First_name"]."\",";
		$data .= "\"patientSurname\":\"".$row["Surname"]."\",";
		$data .= "\"dateSeen\":\"".date("d/m/Y", strtotime($row["appointment_datetime"]))."\",";
		$data .= "\"timeSeen\":\"".date("H:i", strtotime($row["appointment_datetime"]))."\"}";
		
	}
	
	$data .= "]}";
	//$fp = fopen("a.txt", "w");
	//fwrite($fp, $html);
	//fclose($fp);
	echo JsonCharFilter($data);
?>